import 'package:flutter/material.dart';
import 'package:aio/aio.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/manager/audit_manager.dart';
import 'package:app/src/presenter/review_presenter.dart';
import 'package:app/src/ui/app_ui.dart';
import 'package:app/src/ui/route/works/public/items/ui_attachment.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_contractInfo.dart';
import 'package:app/src/ui/route/works/public/items/ui_customersInfo.dart';
import 'package:app/src/ui/route/works/public/items/ui_new_customer.dart';
import 'package:app/src/ui/route/works/public/items/ui_node_list.dart';
import 'package:app/src/ui/route/works/public/items/ui_note.dart';
import 'package:app/src/ui/route/works/public/items/ui_payment.dart';
import 'package:app/src/ui/route/works/public/acom/ui_product.dart';
import 'package:app/src/ui/route/works/public/items/ui_specialclauses.dart';
import 'package:app/src/ui/route/works/public/review_details_ui.dart';
import 'package:app/src/ui/route/works/public/review_submitted.dart';

///合同审核详情
class ContractDetailsRoute extends StatefulWidget {
  bool onlyBack = false;//只有返回键；

  ContractDetailsRoute({bool onlyBack = false}) {
    this.onlyBack = onlyBack;
  }

  @override
  _State createState() => _State();
}

class _State extends State<ContractDetailsRoute> {
  _Presenter presenter = _Presenter();

  @override
  void initState() {
    super.initState();
    presenter.getContractapplygetinfoWithDelay(context); //获取审核详情数据
  }

  @override
  Widget build(BuildContext context) {
    return ReviewDetailsUi.build(context, presenter, _body);
  }

  ///产品搜索条件实体类
  SearchProduct searchProduct = SearchProduct();

  Widget _body(BuildContext context) {
    if (presenter?.mDatas == null) {
      return AppUi.getEmptyView();
    }
    List<Widget> children = [];
    children.add(UiNewCustomer.build(
        context, presenter?.mDatas?.ContractInfo)); //此客户是新客户
    children.add(UiCustomersInfo.build(
        context,
        presenter?.mDatas?.CustomersInfo,
        presenter?.mOldDatas?.CustomersInfo)); //客户信息
    children.add(UiContractInfo.build(context, presenter?.mDatas?.ContractInfo,
        presenter?.mOldDatas?.ContractInfo)); //基本信息（合同信息）
    children.add(UiPayment.build(
        context, presenter?.mDatas?.ContractPaymentTermsCopy)); //付款方式
    children.add(UiPayment.buildWithLast(
        context, presenter?.mDatas?.ContractFinalPaymentCopy)); //末批发货
    children.add(UiSpecialClauses.build(
        context, presenter?.mDatas?.SpecialClausesList)); //特殊加工
    children.add(UiAttachment.build(context, presenter?.mDatas?.FileList)); //附件
    children.add(UiNote.build(
        context,
        presenter?.mDatas?.ContractInfo?.ContractContent,
        presenter?.mOldDatas?.ContractInfo?.ContractContent,
        title: AppStrings.of(context).ContractNote)); //合同备注
    children.add(UiProduct.build(
        context,
        searchProduct,
        presenter?.mDatas?.ProductList,
        presenter?.mOldDatas?.ProductList,false)); //产品信息
    children.add(UiNoteList.build(context, presenter?.mDatas?.NodeList)); //审核日志
    return Column(
      children: [
        Expanded(child: UiBase.listView(context, children)),
        Visibility(
            child: ReviewSubmittedStateful(
              presenter?.mDatas,
              onlyBack: widget.onlyBack,
            ),
            visible: presenter?.mDatas != null)
      ],
    );
  }
}

class _Presenter extends ReviewPresenter {}
